<!DOCTYPE HTML>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
<script type="text/javascript" src="/admin/lib/html5shiv.js"></script>
<script type="text/javascript" src="/admin/lib/respond.min.js"></script>
<![endif]-->
    <link href="/admin/static/h-ui/css/H-ui.css" rel="stylesheet" type="text/css" />
    <link href="/admin/static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
    <link href="/admin/static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
    <link href="/admin/lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />

    <!--[if IE 6]>
<script type="text/javascript" src="/admin/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
    <title>后台登录</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <style>
            /* input.error,
            select.error,
            textarea.error {
                background-color: #fbe2e2;
                border-color: #c66161;
                color: #c00;
            }
        
            label.error {
                position: absolute;
                right: 10px;
                top: 10px;
                color: #ef392b;
                font-size: 12px;
            } */
        </style>
</head>

<body>
    <div class="header"></div>
    <div class="loginWraper">
        <div id="loginform" class="loginBox">
            <form class="form form-horizontal" autocomplete="off" id="form-login">
                <div class="row cl">
                    <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60d;</i></label>
                    <div class="formControls col-xs-8">
                        <input id="username" name="username" type="text" placeholder="用户名" autocomplete="on" class="input-text size-L" >
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60e;</i></label>
                    <div class="formControls col-xs-8">
                        <input id="password" name="password" type="password" placeholder="密码" class="input-text size-L" >
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe685;</i></label>
                    <div class="formControls col-xs-8">
                        <input name="captcha" class="input-text size-L" type="text" placeholder="验证码" style="width:150px;" maxlength="4" >
                    </div>
                    <img src="{{ captcha_src('flat') }}" alt="验证码"> <a id="kanbuq" href="javascript:;">看不清，换一张</a>
                </div>
                @csrf
                {{-- <div class="row cl">
                    <div class="formControls col-xs-8 col-xs-offset-3">
                        <label for="online">
                            <input type="checkbox" name="online" id="online" value="1"> 下次自动登录
                        </label>
                    </div>
                </div> --}}
                <br>
                <div class="row cl">
                    <div class="formControls col-xs-8 col-xs-offset-3">
                        <input name="" type="submit" class="btn btn-success radius size-L" value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;">&emsp;&emsp;&nbsp;&nbsp;
                        <input name="" type="reset" class="btn btn-default radius size-L"  value="&nbsp;取&nbsp;&nbsp;&nbsp;&nbsp;消&nbsp;">
                    <a href="/admin/public/reg" class="ml-40">立即注册</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="footer">Copyright 你的公司名称 by H-ui.admin v3.1</div>
    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.form.js"></script>
    <script src="/admin/lib/layui-v2.4.5/layui/layui.js"></script> 

    <script>
        $(function(){
            layui.use(['layer', 'form'], function(){
                var layer = layui.layer;
                // ,form = layui.form;
/*********此处为全局变量定义区域-----开始***********/
                //layer弹窗的索引，关闭layer时要用到
                var index2;
                //获取验证码的地址  
                var src=$('img').attr('src');

/*********此处为全局变量定义区域-----结束***********/
                //点击切换验证码
                $('#kanbuq').click(function(){
                    $('img').attr('src',src + '=' + Math.random());
                });

                //以JavaScript弹窗形式输出错误的内容
                @if ($errors->any())  
                    var allError = '';
                    @foreach ($errors -> all() as $error) 
                        allError += "{{$error}}<br/>";
                    @endforeach 
                    //输出错误信息 
                    layer.open({
                        content:allError,
                        title:false,
                        type: 0,
                        icon: 5,
                        // skin: 'layui-layer-molv',
                        btn:'',
                        closeBtn: 2, //右上角关闭按钮风格  0无,1默认,2
                        shadeClose: true, //开启遮罩关闭
                        time:0,
                        anim:6,//弹出动画
                    }); 
                @endif

                $("#form-login").validate({
                    rules:{
                        username:{
                            required:true,
                            notSpace:true,
                        },
                        password:{
                            required:true,
                        },
                        captcha:{
                            required:true,
                            minlength:4, 
                            // maxlength:4,//直接写在input内，可以限制只能输入4个字符
                            isCaptcha:true,
                        },
                    },
                    // onkeyup:false,  //建议关闭
                    // focusCleanup:false,//建议关闭
                    success:"valid",
                    submitHandler:function(form){
                        $(form).ajaxSubmit({ 
                            type: 'post', 
                            url: "check",//自己提交给自己可以不写url   
                            //beforeSend  beforeSubmit
                            beforeSend : function () { 
                                //0.4透明度 白色遮罩
                                index2 = layer.load(2,{ shade: [0.3,'#fff'] }); 
                            },
                            complete : function () { 
                                layer.close(index2); 
                            },
                            success: function(data) {
                                //判断注册结果 
                                if(data === '1'){ 
                                    window.location.href="/admin/index/index";
                                }else if(data === '0'){
                                    layer.open({
                                        content:'用户名或密码错误！',
                                        title:false,
                                        type: 0,
                                        icon: 5,
                                        // skin: 'layui-layer-molv',
                                        btn:'',
                                        closeBtn: 2, //右上角关闭按钮风格  0无,1默认,2
                                        shadeClose: true, //开启遮罩关闭
                                        time:0,
                                        anim: 6,//弹出动画
                                    });    
                                }
                                else{
                                    // 更新验证码
                                    $('img').attr('src',src + '=' + Math.random());
                                    layer.msg('登录失败!', { icon: 2, time: 5000 }); 
                                } 
                            }, 
                            error: function(data) {
                                // 更新验证码
                                $('img').attr('src',src + '=' + Math.random());
                                if (data.status==422) {
                                    // var json=JSON.parse(data.responseText);
                                    var json=$.parseJSON(data.responseText);
                                    allError='';
                                    $.each(json.errors,function (index,el) {
                                        allError += el + '<br>'; 
                                    });
                                    //输出错误信息 
                                    layer.open({
                                        content:allError,
                                        title:false,
                                        type: 0,
                                        icon: 5,
                                        // skin: 'layui-layer-molv',
                                        btn:'',
                                        closeBtn: 2, //右上角关闭按钮风格  0无,1默认,2
                                        shadeClose: true, //开启遮罩关闭
                                        time:0,
                                        anim: 6,//弹出动画
                                    });    
                                } else {
                                    console.log(data);
                                    ajax_error(data);
                                }
                            }///error---end
                        }); //ajaxSubmit---end
                    }//submitHandler---end
                });//validate---end
            });//layui.use---end
        });//$(function()---end
    </script>
</body>

</html>